//
// sai.cpp
// SAI
// System Administrator Interface (SAI) / Business Transactions for SAI
// Copyright (C) 2003, 2004, 2005 eXegeSys, Inc.
// Copyright (C) 2008 Bruce A. James
//
// This program is part of the Protea Project.
//
// The Protea Project is free software; you can redistribute it and/or modify it 
// under the terms of the GNU General Public License as published by the 
// Free Software Foundation, either version 3 of the License, or (at your 
// option) any later version.
//
// The Protea Project is distributed in the hope that it will be useful, but 
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
// for more details.
// 
// You should have received a copy of the GNU General Public License along 
// with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Please send correspondence to:
// 
// theproteaproject@gmail.com
//

/////
//
//  System Administrator Interface (SAI) program
//
//	Handles all system administration tasks.  This includes reviewing
//	and modifying system variables, messages, jobs, job schedules,
//	processes, security and license tracking, as well as integrating
//	the Customizer, Designer, and Prep applications.
//
/////
#include "../../SDK/ToolsInterface.h"
#include "../defns2.h"
using namespace ProteaApp2;

#include <iostream>


TRANSACTION_CODE( HandleSAITransaction ) {
	START_TXN( HandleSAITransaction );

		XCMsgPort* port = transaction->GetSource();
		XCToolsMessage* msg;

		// Forward transaction to GCS
		XCMessageList* list = transaction->GetFirstMessage();
		while (list) {
			msg = list->msg;
			msg->SetHeader( msg_trans, src_int, dest_gcs, false, true );
			App->SendMessage( port, App->GetParent(), msg );
			list = list->next;
		};

		// Forward header
		msg = transaction->GetHeader();
		msg->SetHeader( msg_trans, src_int, dest_gcs, false, true );
		App->SendMessage( port, App->GetParent(), msg );

		printf( "Forwarded message to GCS\n" );

	CLEANUP_TXN();

	// Signal to send no reply message
	printf( "Signal no reply message!\n" );
	RAISETOOLSERROR( 0 );

	END_TXN();
};

extern "C" {

__EXPORT bool XCTransactionCode( XCTransRegServer* svr ) {
	svr->RegisterTransaction( TRANS_REVALLPROCESS, HandleSAITransaction );
	svr->RegisterTransaction( TRANS_SETTRACELEVEL, HandleSAITransaction );
	svr->RegisterTransaction( TRANS_SETLISTENERPORT, HandleSAITransaction );
	svr->RegisterTransaction( TRANS_UPDATEAPPL, HandleSAITransaction );
//	svr->RegisterTransaction( TRANS_UPDATEINT, HandleSAITransaction );
	svr->RegisterTransaction( TRANS_SHUTDOWN, HandleSAITransaction );
	svr->RegisterTransaction( TRANS_PROCESSDETAIL, HandleSAITransaction );
	return true;
};

};
